﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents an individual frame in an HTML frameset.
    /// </summary>
    [Serializable]
    [Obsolete("Deprecated in HTML5 - use <div>s and CSS or <iframe>s instead.")]
    [Standalone]
    public class Frame : Element {
        private string _src;
        private string _name;
        private bool _noresize;
        private bool? _scrollbar;
        private int? _marginheight;
        private int? _marginwidth;
        private int? _frameborder;

        /// <summary>
        /// Constructs a new Frame element.
        /// </summary>
        public Frame() { }

        /// <summary>
        /// Constructs a new Frame element with the given source URL.
        /// </summary>
        /// <param name="src">The source URL of this Frame.</param>
        public Frame(string src) {
            _src = src;
        }

        /// <summary>
        /// Constructs a new Frame element with the given source URL and name.
        /// </summary>
        /// <param name="src">The source URL of this Frame.</param>
        /// <param name="name">The name of this Frame.</param>
        public Frame(string src, string name) {
            _src = src;
            _name = name;
        }

        /// <summary>
        /// Determines the URL of the frame's data.
        /// </summary>
        public string Src {
            get { return _src; }
            set { _src = value; }
        }

        /// <summary>
        /// Determines the name of the frame.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines whether or not to let the user resize the frame.
        /// </summary>
        public bool NoResize {
            get { return _noresize; }
            set { _noresize = value; }
        }

        /// <summary>
        /// Determines whether or not to show a scrollbar if it is necessary.
        /// </summary>
        public bool? Scrollbar {
            get { return _scrollbar; }
            set { _scrollbar = value; }
        }

        /// <summary>
        /// Determine the height of the frame's margin, in pixels.
        /// </summary>
        public int? MarginHeight {
            get { return _marginheight; }
            set { _marginheight = value; }
        }

        /// <summary>
        /// Determine the width of the frame's margin, in pixels.
        /// </summary>
        public int? MarginWidth {
            get { return _marginwidth; }
            set { _marginwidth = value; }
        }

        /// <summary>
        /// Determines the size of the frame's border, in pixels.
        /// </summary>
        public int? FrameBorder {
            get { return _frameborder; }
            set { _frameborder = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _frameborder, "frameborder");
            AttributeWriter.Write(sb, _marginheight, "marginheight");
            AttributeWriter.Write(sb, _marginwidth, "marginwidth");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _noresize, "noresize");
            if (_scrollbar != null) {
                AttributeWriter.Write(sb, _scrollbar.Value ? "yes" : "no",
                    "scrollbar");
            }
            AttributeWriter.Write(sb, _src, "src");
        }
    }
}
